﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Utils
{
    public interface ICacheStrategy
    {
        ICacheStrategy Change(int db);

        bool HasKey(string key);


        /// <summary>
        /// 加入当前对象到缓存中
        /// </summary>
        /// <param name="key">对象的键值</param>
        /// <param name="value">缓存的对象</param>
        /// <param name="seconds">缓存的时间，单位秒默认 7200 秒 2小时</param>
        void Add<T>(string key, T value, int seconds);

        /// <summary>
        /// 移除指定ID的对象
        /// </summary>
        /// <param name="key">对象的键值</param>
        void Remove(string key);

        /// <summary>
        /// 移除所有对象
        /// </summary>
        void RemoveAll();

        /// <summary>
        /// 返回指定ID的对象
        /// </summary>
        /// <param name="key">对象的键值</param>
        /// <returns></returns>
        object Get(string key);

        /// <summary>
        /// 返回指定ID的对象
        /// </summary>
        /// <param name="key">对象的键值</param>
        /// <returns></returns>
        T Get<T>(string key);

        void RemoveStartsWith(string key);
        void DeleteHash(string key, string field);
        void AddHash<T>(string key, string field, T value);

        Dictionary<string, T> GetHashAll<T>(string key);

        void SetHash<T>(string key, IDictionary<string, T> fields);

        T GetHash<T>(string key, string field);

        void CloseChange();
    }
}
